package com.example.young.peopleaccommodationms;

import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;

import services.BasicService;

public class ServiceDemo extends AppCompatActivity implements View.OnClickListener{

    private static String TAG = "ServiceDemo";

    public Button startService_btn;
    public Button pauseService_btn;
    public Button stopService_btn;
    public Button bindService_btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_service_demo);
        startService_btn = (Button) findViewById(R.id.service_demo_start);
        pauseService_btn = (Button) findViewById(R.id.service_demo_pause);
        stopService_btn = (Button) findViewById(R.id.service_demo_stop);
        bindService_btn = (Button) findViewById(R.id.service_demo_bind);

        startService_btn.setOnClickListener(this);
        pauseService_btn.setOnClickListener(this);
        stopService_btn.setOnClickListener(this);
        bindService_btn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.service_demo_start:
                startService(new Intent(BasicService.ACTION));
            case R.id.service_demo_pause:
                break;
            case R.id.service_demo_stop:
                break;
            case R.id.service_demo_bind:
                bindService(new Intent(BasicService.ACTION),conn, BIND_AUTO_CREATE);
            default:
                break;
        }
    }

    ServiceConnection conn = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            Log.v(TAG, "onServiceStarted");
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            Log.v(TAG, "onServiceDisconnected");
        }
    };

    @Override
    protected void onDestroy() {
        Log.v(TAG, "unbindService");
        unbindService(conn);
        super.onDestroy();
    }
}
